﻿using System.Web.UI.WebControls;
using Medianamik.Globalization;

namespace Medianamik.UI.Controls
{
    public class RequiredCheckBox : Checkbox
    {
        protected override void CreateControlHierarchy(bool pUseDataSource)
        {
            var validator = new CustomValidator();
            Controls.Add(validator);
            validator.ServerValidate += ValidateChecked;

            if (pUseDataSource)
            {
                validator.ValidationGroup = ValidationGroupName;
                validator.ErrorMessage = Label + " " +
                    Translator.Translate("Medianamik_Controls", "RequiredCheckboxMessage");
                validator.Display = ValidatorDisplay.None;
            }

            base.CreateControlHierarchy(pUseDataSource);
        }

        void ValidateChecked(object source, ServerValidateEventArgs args)
        {
            args.IsValid = chkCtrl.Checked;
        }
    }
}
